/**
 * BCJS 0.3.1 (21 MAY 2010)
 * A Brightcove JavaScript Library
 *
 * AUTHOR:
 *       Matthew Congrove, Professional Services Engineer, Brightcove
 *       Brian Franklin, Professional Services Engineer, Brightcove
 *       Jesse Streb, Professional Services Engineer, Brightcove
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to
 * deal in the Software without restriction, including without limitation the
 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
 * sell copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE. YOU AGREE TO RETAIN IN THE SOFTWARE AND ANY MODIFICATIONS TO THE
 * SOFTWARE THE REFERENCE URL INFORMATION, AUTHOR ATTRIBUTION AND CONTRIBUTOR
 * ATTRIBUTION PROVIDED HEREIN.
 *
 * BCJS incorporates the following libraries:
 *
 *       Kudos-JS - Brightcove Javascript SDK
 *       Copyright (C) 2009 Brian Franklin, Matthew Congrove
 *       http://www.kudos-js.com
 *
 * BCJS requires the following libraries:
 *
 *       NWMatcher - http://javascript.nwbox.com/NWMatcher
 */

var BCJS = function() {
	this.init = function() {
		this.DOM = new BCJS.DOM();
		this.DOM.init();
		this.EXP = new BCJS.EXP();
		this.EXP.init();
		this.UI = new BCJS.UI();
		this.UI.init();
		this.API = new BCJS.API();
		this.API.init();

		this.$ = this.DOM.select;
		this.$$ = this.DOM.hasMatch;

		this.debug = false;

		this.addScripts();

		this.browser = this.browser();
		this.isSafari = false;
		this.isFirefox = false;
		this.isIE = false;
		this.isIE6 = false;
		this.isIE7 = false;

		if(this.browser[1] == "firefox") {
			this.isFirefox = true;
		} else if(this.browser[1] == "safari") {
			this.isSafari = true;
		} else if(this.browser[1] == "explorer") {
			this.isIE = true;

			if(this.browser[2] < 7) {
				this.isIE6 = true;
			} else if(this.browser[2] < 8) {
				this.isIE7 = true;
			}
		}
	};

	this.addScripts = function() {
		var pScripts = document.getElementsByTagName("script");
		var experienceScriptFound = false;
		var modulesScriptFound = false;

		for(var i = 0; i < pScripts.length; i++) {
			if(pScripts[i].src == "http://admin.brightcove.com/js/BrightcoveExperiences.js") {
				experienceScriptFound = true;
			} else if(pScripts[i].src == "http://admin.brightcove.com/js/APIModules_all.js") {
				modulesScriptFound = true;
			}
		}

		if(!experienceScriptFound) {
			BCJS.error("Experience script not found. Added by BCJS.");

			var pEl = document.createElement("script");
			pEl.src = "http://admin.brightcove.com/js/BrightcoveExperiences.js";
			pEl.type = "text/javascript";
			document.getElementsByTagName("head")[0].appendChild(pEl);
		}

		if(!modulesScriptFound) {
			BCJS.error("API Modules script not found. Added by BCJS.");

			var pEl = document.createElement("script");
			pEl.src = "http://admin.brightcove.com/js/APIModules_all.js";
			pEl.type = "text/javascript";
			document.getElementsByTagName("head")[0].appendChild(pEl);
		}

		var matcherScriptFound = typeof NW == "undefined" ? false : true;

		if(typeof NW == "undefined") {
			BCJS.error("NWMatcher script not found.");
		}
	};

	this.loadQueue = function(pFunc) {
		if(typeof window.addEventListener != "undefined") {
			window.addEventListener("load", pFunc, false);
		} else if(typeof window.attachEvent != "undefined") {
			window.attachEvent("onload", pFunc);
		} else {
			if(window.onload !== null) {
				var oldOnload = window.onload;

				window.onload = function(e) {
					oldOnload(e);

					window[pFunc]();
				};
			} else {
				window.onload = pFunc;
			}
		}
	};

	this.ajax = function(pSrc, pCallback, pPost, pParams) {
		if(window.XMLHttpRequest) {
			httpRequest = new XMLHttpRequest();
			if(httpRequest.overrideMimeType) {
				httpRequest.overrideMimeType("text/xml");
			}
		} else if(window.ActiveXObject) {
			try {
				httpRequest = new ActiveXObject("Msxml2.XMLHTTP");
			} catch(e1) {
				try {
					httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
				} catch(e2) {}
			}
		}

		if(!httpRequest) {
			return false;
		}

		httpRequest.onreadystatechange = function() {
			if(httpRequest.readyState == 4) {
				if(httpRequest.status == 200) {
					if(!pCallback) {
						return httpRequest.responseXML;
					} else {
						pCallback(httpRequest.responseXML);
					}
				}
			}
		};

		if(!pPost) {
			if(!pCallback) {
				httpRequest.open("GET", pSrc, false);
			} else {
				httpRequest.open("GET", pSrc, true);
			}

			httpRequest.send("");
		} else {
			httpRequest.open("POST", pSrc, true);
			httpRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
			httpRequest.setRequestHeader("Content-length", pParams.length);

			httpRequest.send(pParams);
		}
	};

	this.browser = function() {
		var type;
		var os;
		var version;

		var browser = new Array(
			{string: navigator.userAgent, subString: "Chrome", identity: "Chrome"},
			{string: navigator.userAgent, subString: "OmniWeb", versionSearch: "OmniWeb/", identity: "OmniWeb"},
			{string: navigator.vendor, subString: "Apple", identity: "Safari", versionSearch: "version"},
			{prop: window.opera, identity: "Opera"},
			{string: navigator.vendor, subString: "iCab", identity: "iCab"},
			{string: navigator.vendor, subString: "KDE", identity: "Konqueror"},
			{string: navigator.userAgent, subString: "Firefox", identity: "Firefox"},
			{string: navigator.vendor, subString: "Camino", identity: "Camino"},
			{string: navigator.userAgent, subString: "Netscape", identity: "Netscape"},
			{string: navigator.userAgent, subString: "MSIE", identity: "Explorer", versionSearch: "MSIE"},
			{string: navigator.userAgent, subString: "Gecko", identity: "Mozilla", versionSearch: "rv"},
			{string: navigator.userAgent, subString: "Mozilla", identity: "Netscape", versionSearch: "Mozilla"}
		);

		var system = new Array(
			{string: navigator.platform, subString: "Win", identity: "windows"},
			{string: navigator.platform, subString: "Mac", identity: "mac"},
			{string: navigator.platform, subString: "Linux", identity: "linux"}
		);

		var g = function(d) {
			for(var i = 0; i < d.length; i++) {
				var s = d[i].string;
				var p = d[i].prop;

				type = d[i].versionSearch || d[i].identity;

				if(s) {
					if(s.indexOf(d[i].subString) != -1) {
						return d[i].identity;
					}
				} else if(p) {
					return d[i].identity;
				}
			}
		};

		var h = function(s, t) {
			var i = s.indexOf(t);

			if(i == -1) {
				return;
			}

			return parseFloat(s.substring(i + t.length + 1));
		};

		browser = g(browser) || "unknown";
		version = h(navigator.userAgent, type) || h(navigator.appVersion, type) || "unknown";
		browser = browser.toLowerCase();
		os = g(system) || "unknown";

		return new Array(os, browser, version);
	};

	this.dimensions = function() {
		var win_width;
		var win_height;
		var scroll_width;
		var scroll_height;

		if(typeof window.innerWidth != "undefined") {
			win_width = window.innerWidth;
			win_height = window.innerHeight;
		} else if(typeof document.documentElement != "undefined" && typeof document.documentElement.clientWidth != "undefined" && document.documentElement.clientWidth != 0) {
			win_width = document.documentElement.clientWidth;
			win_height = document.documentElement.clientHeight;
		} else {
			win_width = document.getElementsByTagName("body")[0].clientWidth;
			win_height = document.getElementsByTagName("body")[0].clientHeight;
		}

		if(typeof(window.pageYOffset) == "number") {
			scroll_width = window.pageXOffset;
			scroll_height = window.pageYOffset;
		} else if(document.body && (document.body.scrollLeft || document.body.scrollTop)) {
			scroll_width = document.body.scrollLeft;
			scroll_height = document.body.scrollTop;
		} else if(document.documentElement && (document.documentElement.scrollLeft || document.documentElement.scrollTop)) {
			scroll_width = document.documentElement.scrollLeft;
			scroll_height = document.documentElement.scrollTop;
		}

		if(typeof(win_width) == "undefined") { win_width = 0; }
		if(typeof(win_height) == "undefined") { win_height = 0; }
		if(typeof(scroll_width) == "undefined") { scroll_width = 0; }
		if(typeof(scroll_height) == "undefined") { scroll_height = 0; }

		return new Array(win_width, win_height, scroll_width, scroll_height);
	};

	this.getNum = function(pNum) {
		var ret = "";
		var bool = false;

		if(pNum.indexOf("px") > -1) {
			bool = true;
			ret = parseInt(pNum.substring(0, pNum.indexOf("px")));
		} else {
			ret = parseInt(pNum);
		}

		return new Array(ret, bool);
	};

	this.time = function(pNum) {
		pNum = new Number(pNum / 1000);
		var h = Math.floor(pNum / 3600);
		var m = Math.floor(pNum % 3600 / 60);
		var s = Math.floor(pNum % 3600 % 60);
		return ((h > 0 ? h + ":" : "") + (m > 0 ? (h > 0 && m < 10 ? "0" : "") + m + ":" : "0:") + (s < 10 ? "0" : "") + s);
	};

	this.getCookie = function(pName) {
		var start = document.cookie.indexOf(pName + "=");
		var len = start + pName.length + 1;

		if((!start) && (pName != document.cookie.substring(0, pName.length))) {
			return null;
		}

		if(start == -1) {
			return null;
		}

		var end = document.cookie.indexOf(";", len);

		if(end == -1) {
			end = document.cookie.length;
		}

		return unescape(document.cookie.substring(len, end));
	};

	this.setCookie = function(pName, pValue, pExpires, pOptions) {
		if(pOptions === undefined) {
			pOptions = {};
		}

		if(pExpires) {
			var expires_date = new Date();
			expires_date.setDate(expires_date.getDate() + pExpires)
		}

		document.cookie = pName + "=" + escape(pValue) +
			((pExpires) ? ";expires="+expires_date.toGMTString() : "") +
			((pOptions.path) ? ";path=" + pOptions.path : "") +
			((pOptions.domain) ? ";domain=" + pOptions.domain : "") +
			((pOptions.secure) ? ";secure" : "");
	};

	this.deleteCookie = function(pName, pPath, pDomain) {
		if(BCJS.getCookie(pName)) {
			document.cookie = pName + "=" +
			((pPath) ? ";path=" + pPath : "") +
			((pDomain) ? ";domain=" + pDomain : "") +
			";expires=Thu, 01-Jan-1970 00:00:01 GMT";
		}
	};

	this.base64 = function(pType, pString) {
		var key = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
		var keyRe = new RegExp("[^" + key + "=]", "g");

		if(pType == "encode") {
			var i = 0;
			var output = "";
			var len = pString.length;
			var padding = 3 - (len % 3);

			while(i < len) {
				var byte1 = pString.charCodeAt(i++);
				var byte2 = pString.charCodeAt(i++) || 0;
				var byte3 = pString.charCodeAt(i++) || 0;
				var index1 = byte1 >> 2;
				var index2 = (byte1 & 3) << 4 | byte2 >> 4;
				var index3 = (byte2 & 15) << 2 | byte3 >> 6;
				var index4 = byte3 & 63;

				output += key.charAt(index1) + key.charAt(index2) + key.charAt(index3) + key.charAt(index4);
			}

			if(padding) {
				output = output.slice(0, output.length - padding) + (padding == 1 ? "=" : "==");
			}

			return output;
		} else {
			pString = pString.replace(keyRe, "");

			var i = 0;
			var output = "";
			var len = pString.length;
			var padding = len - pString.indexOf("=");

			while(i < len) {
				var byte1 = key.indexOf(pString.substr(i++, 1));
				var byte2 = key.indexOf(pString.substr(i++, 1));
				var byte3 = key.indexOf(pString.substr(i++, 1));
				var byte4 = key.indexOf(pString.substr(i++, 1));
				var char1 = byte1 << 2 | byte2 >> 4;
				var char2 = ((byte2 & 15) << 4) | (byte3 >> 2);
				var char3 = ((byte3 & 3) << 6) | byte4 & 63;

				output += String.fromCharCode(char1) + String.fromCharCode(char2) + String.fromCharCode(char3);
			}

			if(padding) {
				output = output.substr(0, output.length - padding);
			}

			return output;
		}
	};

	this.param = function(pName) {
		pName = pName.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");

		var regexS = "[\\?&]" + pName + "=([^&#]*)";
		var regex = new RegExp(regexS);
		var results = regex.exec(window.location.href);

		if(results == null) {
			return "";
		} else {
			return results[1];
		}
	};

	this.error = function(pData) {
		if(this.debug) {
			if(typeof console !== "undefined") {
				BCJS.error("" + pData);
			}
		}
	};

	this.UI = function() {
		this.init = function() {
			this.isFading = false;
		};

		this.tween = function(pEl, pType, pNewValue, pTime, pCallback) {
			if(typeof(pEl) == "string") {
				pEl = BCJS.DOM.select(pEl)[0];
			}

			if(pType == "opacity") {
				if(BCJS.isIE) {
					pType = "filter";
				}
			}

			if(pTime == 0 || typeof(pTime) != "number") {
				pTime = 1;
			}

			var pStartValue = BCJS.getNum(pEl.style[pType])[0];
			var pValueDistance = pNewValue - pStartValue;
			var pTimeStart = new Date().getTime();
			var pTimeEnd = pTimeStart + pTime;

			BCJS.UI.tweenExecute(pEl, pType, pStartValue, pValueDistance, pTime, pTimeEnd, pCallback);
		};

		this.tweenExecute = function(pEl, pType, pStartValue, pValueDistance, pTime, pTimeEnd, pCallback) {
			var pCurrentTime = new Date().getTime();
			var pTimeRemaining = Math.max(0, pTimeEnd - pCurrentTime);
			var pCurrentMove;

			if(pType == "top" || pType == "right" || pType == "bottom" || pType == "left") {
				pCurrentMove = Math.round((pValueDistance - (Math.pow(pTimeRemaining, 3) / Math.pow(pTime, 3)) * pValueDistance) * 10) / 10;
			} else {
				pCurrentMove = Math.round((pValueDistance - (pTimeRemaining / pTime) * pValueDistance) * 10) / 10;
			}

			if(pTimeRemaining <= 0 || pValueDistance > 10) {
				pCurrentMove = parseInt(pCurrentMove);
			}

			if(pType != "filter") {
				var isPx = BCJS.getNum(pEl.style[pType])[1];
			}

			if(isPx) {
				pEl.style[pType] = (pStartValue + pCurrentMove) + "px";
			} else {
				if(pType == "filter") {
					pEl.style[pType] = "alpha(opacity=" + ((pStartValue + pCurrentMove) * 100) + ")";
				} else {
					pEl.style[pType] = (pStartValue + pCurrentMove);
				}
			}

			if(pTimeRemaining > 0) {
				setTimeout(
					function() {
						BCJS.UI.tweenExecute(pEl, pType, pStartValue, pValueDistance, pTime, pTimeEnd, pCallback);
					},
					10
				);
			} else {
				if(typeof(pCallback) == "function") {
					pCallback();
				}
			}
		};

		this.hide = function(pEl) {
			if(typeof(pEl) == "string") {
				pEl = BCJS.DOM.select(pEl)[0];
			}

			if(pEl.style["display"] != "none" && pEl.style["display"] != "hidden") {
				pEl.style["display"] = "none";
			}
		};

		this.show = function(pEl) {
			if(typeof(pEl) == "string") {
				pEl = BCJS.DOM.select(pEl)[0];
			}

			if(pEl.style["display"] == "none" || pEl.style["display"] == "hidden") {
				pEl.style["display"] = "block";
			}
		};

		this.toggle = function(pEl) {
			if(typeof(pEl) == "string") {
				pEl = BCJS.DOM.select(pEl)[0];
			}

			if(pEl.style["display"] == "none" || pEl.style["display"] == "hidden") {
				pEl.style["display"] = "block";
			} else {
				pEl.style["display"] = "none";
			}
		};

		this.center = function(pEl, pType) {
			if(typeof(pEl) == "string") {
				pEl = BCJS.DOM.select(pEl)[0];
			}

			var elWidth;
			var elHeight;

			if(pEl.offsetWidth) {
				elWidth = pEl.offsetWidth;
			} else {
				elWidth = BCJS.getNum(pEl.style["width"])[0];
			}

			if(pEl.offsetHeight) {
				elHeight = pEl.offsetHeight;
			} else {
				elHeight = BCJS.getNum(pEl.style["height"])[0];
			}

			var win = BCJS.dimensions();

			if(pType == "fixed") {
				var newX = ((win[0] / 2) - (elWidth / 2));
				var newY = ((win[1] / 2) - (elHeight / 2));
			} else {
				var newX = ((win[0] / 2) - (elWidth / 2) + win[2]);
				var newY = ((win[1] / 2) - (elHeight / 2) + win[3]);
			}

			if(newY < 0) {
				newY = 0;
			}

			if(newX < 0) {
				newX = 0;
			}

			pEl.style["left"] = newX + "px";
			pEl.style["top"] = newY + "px";
		};

		this.accordion = function(pId, pClass, pSpeed) {
			var pEls = BCJS.DOM.select("." + pClass);

			for(var i = 0; i < pEls.length; i++) {
				if(pEls[i].id == pId) {
					BCJS.UI.blind(pEls[i].id, pSpeed);
				} else {
					pContainer = BCJS.DOM.select("#" + pEls[i].id + "_BCJSC")[0];

					if(pContainer) {
						BCJS.UI.blindClose(pContainer.id, pSpeed);
					}
				}
			}
		}

		this.blind = function(pId, pSpeed) {
			var pContainer = BCJS.DOM.select("#" + pId + "_BCJSC")[0];

			if(BCJS.DOM.select("#" + pId + "_BCJSC")[0]) {
				if(BCJS.getNum(pContainer.style["height"])[0] > 0) {
					BCJS.UI.blindClose(pContainer.id, pSpeed);
				} else {
					var pEl = BCJS.DOM.select("#" + pId)[0];
					var finalHeight = pEl.offsetHeight;

					BCJS.UI.blindOpen(pContainer.id, finalHeight, pSpeed);
				}
			} else {
				BCJS.UI.blindExecute(pId, pSpeed);
			}
		}

		this.blindExecute = function(pId, pSpeed) {
			var pOrigEl = BCJS.DOM.select("#" + pId)[0];
			var pParent = pOrigEl.parentNode;

			var pNewEl = pOrigEl.cloneNode(true);
			pNewEl.style["display"] = "block";

			var pContainer = document.createElement("div");
			pContainer.id = pId + "_BCJSC";
			pContainer.style["height"] = "0px";
			pContainer.style["overflow"] = "hidden";
			pContainer.style["position"] = "relative";

			pParent.insertBefore(pContainer, pOrigEl);
			pParent.removeChild(pOrigEl);

			pContainer = BCJS.DOM.select("#" + pContainer.id)[0];
			pContainer.appendChild(pNewEl);

			pNewEl = BCJS.DOM.select("#" + pId)[0];
			var finalHeight = pNewEl.offsetHeight;
			pNewEl.style["width"] = pNewEl.offsetWidth + "px";
			pNewEl.style["position"] = "absolute";
			pNewEl.style["bottom"] = "0px";

			BCJS.UI.blindOpen(pContainer.id, finalHeight, pSpeed);
		}

		this.blindClose = function(pId, pSpeed) {
			BCJS.UI.tween(
				"#" + pId,
				"height",
				0,
				pSpeed
			);
		}

		this.blindOpen = function(pId, pHeight, pSpeed) {
			BCJS.UI.tween(
				"#" + pId,
				"height",
				pHeight,
				pSpeed
			);
		}
	};

	this.DOM = function() {
		this.init = function() {

		};

		this.match = function(pEl, pAttr) {
			return NW.Dom.match(pEl, pAttr);
		};

		this.select = function(pEl) {
			return NW.Dom.select(pEl);
		};

		this.hasMatch = function(pEl, pAttr) {
			if(typeof(pEl) == "string") {
				pEl = this.select(pEl)[0];
			}

			if(this.match(pEl, pAttr)) {
				return true;
			} else {
				return false;
			}
		};

		this.addClass = function(pEl, pClass) {
			if(typeof(pEl) == "string") {
				pEl = this.select(pEl)[0];
			}

			if(!this.match(pEl, "." + pClass)) {
				pEl.className = pEl.className + " " + pClass;
			}
		};

		this.removeClass = function(pEl, pClass) {
			if(typeof(pEl) == "string") {
				pEl = this.select(pEl)[0];
			}

			if(this.match(pEl, "." + pClass)) {
				var reg = new RegExp("(\\s|^)" + pClass + "(\\s|$)");
				pEl.className = pEl.className.replace(reg, " ");
			}
		};

		this.toggleClass = function(pEl, pClass) {
			if(typeof(pEl) == "string") {
				pEl = this.select(pEl)[0];
			}

			if(!this.match(pEl, "." + pClass)) {
				this.addClass(pEl, pClass);
			} else {
				this.removeClass(pEl, pClass);
			}
		};
	};

	this.EXP = function() {
		this.init = function() {
			this.ad = null;
			this.brightcove = null;
			this.cue = null;
			this.experience = null;
			this.media = null;
			this.social = null;
			this.player = null;

			this.apiEnabled = false;
			this.apiEnabledCount = 0;
			this.apiEnabledTimer = null;

			BCJS.loadQueue(function() {
				BCJS.EXP.apiEnabledTimer = setInterval(
					function() {
						if(this.apiEnabled) {
							clearInterval(BCJS.EXP.apiEnabledTimer);
						} else {
							BCJS.EXP.apiEnabledCount++;

							if(BCJS.EXP.apiEnabledCount == 5) {
								clearInterval(BCJS.EXP.apiEnabledTimer);

								BCJS.error("JavaScript API not enabled.");
							}
						}
					}, 1000
				);
			});

			this.templateLoadedQueue(function(pId) {
				BCJS.EXP.onTemplateLoaded(pId);
			});
		};

		this.templateLoadedQueue = function(pFunc) {
			if(typeof onTemplateLoaded != "undefined") {
				var oldOnTemplateLoaded = onTemplateLoaded;

				onTemplateLoaded = function(pEvent) {
					oldOnTemplateLoaded(pEvent);
					pFunc(pEvent);
				};
			} else {
				onTemplateLoaded = function(pEvent) {
					pFunc(pEvent);
				};
			}
		};

		this.onContentLoaded = function() {
			if(typeof BCJS_contentLoaded == "function") {
				BCJS_contentLoaded();
			}
		};

		this.onCuePoint = function(pData) {
			if(typeof BCJS_cuePoint == "function") {
				BCJS_cuePoint(pData);
			}
		};

		this.onExternalAd = function(pData) {
			if(typeof BCJS_externalAd == "function") {
				BCJS_externalAd(pData);
			}
		};

		this.onMediaComplete = function() {
			if(typeof BCJS_mediaComplete == "function") {
				BCJS_mediaComplete();
			}
		};

		this.onMediaChange = function() {
			if(typeof BCJS_mediaChange == "function") {
				BCJS_mediaChange();
			}
		};

		this.onTemplateLoaded = function(pId) {
			this.apiEnabled = true;

			BCJS.EXP.brightcove = brightcove.getExperience(pId);
			BCJS.EXP.ad = BCJS.EXP.brightcove.getModule(APIModules.ADVERTISING);
			BCJS.EXP.cue = BCJS.EXP.brightcove.getModule(APIModules.CUE_POINTS);
			BCJS.EXP.experience = BCJS.EXP.brightcove.getModule(APIModules.EXPERIENCE);
			BCJS.EXP.content = BCJS.EXP.brightcove.getModule(APIModules.CONTENT);
			BCJS.EXP.social = BCJS.EXP.brightcove.getModule(APIModules.SOCIAL);
			BCJS.EXP.player = BCJS.EXP.brightcove.getModule(APIModules.VIDEO_PLAYER);

			BCJS.EXP.experience.addEventListener(BCExperienceEvent.TEMPLATE_READY, BCJS.EXP.onTemplateReady);
			BCJS.EXP.experience.addEventListener(BCExperienceEvent.CONTENT_LOAD, BCJS.EXP.onContentLoaded);

			if(typeof BCJS_templateLoaded == "function") {
				BCJS_templateLoaded(pId);
			}
		};

		this.onTemplateReady = function() {
			BCJS.EXP.player.addEventListener(BCMediaEvent.COMPLETE, BCJS.EXP.onMediaComplete);
			BCJS.EXP.player.addEventListener(BCMediaEvent.CHANGE, BCJS.EXP.onMediaChange);
			BCJS.EXP.cue.addEventListener(BCCuePointEvent.CUE, BCJS.EXP.onCuePoint);

			if(typeof BCJS_templateReady == "function") {
				BCJS_templateReady();
			}
		};
	};

	this.API = function() {
		this.init = function() {
			this.token = "";
			this.callback = "BCJS.API.flush";
			this.url = "http://api.brightcove.com/services/library";
			this.calls = [
				{ "method":"find_all_videos", "def":false },
				{ "method":"find_playlists_for_player_id", "def":"player_id" },
				{ "method":"find_all_playlists", "def":false },
				{ "method":"find_playlist_by_id", "def":"playlist_id" },
				{ "method":"find_related_videos", "def":"video_id" },
				{ "method":"find_video_by_id", "def":"video_id" },
				{ "method":"find_videos_by_ids", "def":"video_ids" },
				{ "method":"find_videos_by_tags", "def":"or_tags" },
				{ "method":"find_video_by_reference_id", "def":"reference_id" },
				{ "method":"find_video_by_reference_ids", "def":"reference_ids" },
				{ "method":"find_videos_by_user_id", "def":"user_id" },
				{ "method":"find_videos_by_campaign_id", "def":"campaign_id" },
				{ "method":"find_videos_by_text", "def":"text" },
				{ "method":"find_modified_videos", "def":"from_date" },
				{ "method":"find_playlists_by_ids", "def":"playlist_ids" },
				{ "method":"find_playlist_by_reference_id", "def":"reference_id" },
				{ "method":"find_playlists_by_reference_ids", "def":"reference_ids" }
			];
		};

		this.inject = function(pParams) {
			var pEl = document.createElement("script");

			pEl.setAttribute("src", BCJS.API.url + "?" + pParams);
			pEl.setAttribute("type", "text/javascript");

			document.getElementsByTagName("head")[0].appendChild(pEl);

			return true;
		};

		this.find = function(pMethod, pParams) {
			var pDefault = null;
			var pQuery = "";

			pParams = pParams || null;
			pMethod = pMethod.toLowerCase().replace(/(find_)|(_)|(get_)/g, "");

			for(var method in BCJS.API.calls) {
				if(pMethod == BCJS.API.calls[method].method.toLowerCase().replace(/(find_)|(_)|(get_)/g, "")) {
					pMethod = BCJS.API.calls[method].method;
					pDefault = BCJS.API.calls[method].def;
				}
			}

			pQuery = "command=" + pMethod;

			if((typeof pParams == "object") && pParams) {
				for(var pValue in pParams) {
					if(pValue == "selector") {
						pQuery += "&" + pDefault + "=" + pParams[pValue];
					} else {
						pQuery += "&" + pValue + "=" + pParams[pValue];
					}
				}

				if(typeof pParams.callback != "string") {
					pQuery += "&callback=" + this.callback;
				}

				if(typeof pParams.token != "string") {
					pQuery += "&token=" + this.token;
				}
			} else if(pParams) {
				pQuery += "&" + pDefault + "=" + pParams + "&callback=" + this.callback;
				pQuery += "&token=" + this.token;
			} else {
				pQuery += "&token=" + this.token;
				pQuery += "&callback=" + this.callback;
			}

			BCJS.API.inject(pQuery);

			return true;
		};

		this.flush = function(pData) {
			return true;
		};
	};
};

BCJS = new BCJS();
BCJS.init();